#ifndef _MISC_FUNC_H
#define _MISC_FUNC_H

#include <Windows.h>

#include "type.h"

#define SAFE_DELETE(x) \
  if (x) { \
    delete x; \
    x = 0; \
  }

class high_performance_timer
{
public:
  high_performance_timer()
  {
    restart();
  }

  void restart()
  {
    LARGE_INTEGER litmp;
    QueryPerformanceFrequency(&litmp);
    m_Freq = (f64)litmp.QuadPart;
    QueryPerformanceCounter(&litmp);
    m_start = litmp.QuadPart;
  }
  s64 elapsed()
  {
    LARGE_INTEGER litmp;
    QueryPerformanceCounter(&litmp);
    return (s64)((f64)((litmp.QuadPart - m_start) * 1000 * 1000 / m_Freq));
  }

private:
  s64 m_start;
  f64 m_Freq;
};

#endif  // _MISC_FUNC_H
